/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.niedziela12.pai.ejb.dto;

import java.io.Serializable;
import java.util.List;
import com.niedziela12.pai.ejb.entities.Role;
import com.niedziela12.pai.ejb.entities.UserRoles;
import java.util.ArrayList;

/**
 *
 * @author Kamil
 */
public class RoleDTO implements Serializable {
    private static final long serialVersionUID = 1L;
    private Long id;
    private String name;
//    private List<UserRolesDTO> users;

    public RoleDTO(){        
    }

    public RoleDTO(Role role) {
        if (role != null) {
            this.id = role.getId();
            this.name = role.getName();
//            this.users = new ArrayList<UserRolesDTO>();
//            for (UserRoles u : role.getUserRolesList()) {
//                users.add(new UserRolesDTO(u));
//            }
        }
    }
    
    public Role toRole(){
        Role r = new Role();
        r.setId(id);
        r.setName(name);
        List<UserRoles> urs = new ArrayList<UserRoles>();
//        for(UserRolesDTO u : users)urs.add(u.toUserRoles());
        r.setUserRolesList(urs);
        return r;
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

//    public List<UserRolesDTO> getUsers() {
//        return users;
//    }
//
//    public void setUsers(List<UserRolesDTO> users) {
//        this.users = users;
//    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof RoleDTO)) {
            return false;
        }
        RoleDTO other = (RoleDTO) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.niedziela12.pai.ejb.dto.Role[ id=" + id + " ]";
    }
    
}
